Skip to content

Add matrix_opt for cuSPARSE backend#66

Open
tdehoff wants to merge 5 commits intoSparseBLAS:mainfrom
tdehoff:main
Open

Add matrix_opt for cuSPARSE backend#66
tdehoff wants to merge 5 commits intoSparseBLAS:mainfrom
tdehoff:main

Conversation

@tdehoff
Copy link
Copy Markdown

@tdehoff tdehoff commented Mar 25, 2026

Summary:
Adds the following for the cuSPARSE backend: matrix_handle for CSR and CSC formats, SpMM, small updates to SpMV, draft of SpGEMM.

Details:

Since I wasn't able to test SpGEMM, I expect it to have multiple issues.
A simple case of SpMM was verified in the example file.

Merge Checklist:

  • Passing CI
  • Update documentation or README.md
  • Additional Test/example added (if applicable) and passing
  • At least one reviewer approval
  • (optional) Clang sanitizer scan run and triaged
  • Clang formatter applied (verified as part of passing CI)

@yhmtsai yhmtsai self-requested a review April 9, 2026 17:09
Copy link
Copy Markdown
Contributor

@yhmtsai yhmtsai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tdehoff
Excellent work! I have some nit which needs to address.
When it is possible, we would like to have a small pr rather than large pr.
Thus, I will suggest to remove the spgemm part out of this pr because it is not finished and can be in another pr like #54

Comment on lines +47 to +73
//
// Takes in a CSR or CSR_transpose (aka CSC) or CSC or CSC_transpose
// and returns the transpose value associated with it being represented
// in the CSR format (since oneMKL SYCL currently does not have CSC
// format
//
// CSR = CSR + nontrans
// CSR_transpose = CSR + trans
// CSC = CSR + trans
// CSC_transpose -> CSR + nontrans
//
// template <matrix M>
// oneapi::mkl::transpose get_transpose(M&& m) {
// static_assert(__detail::has_csr_base<M> || __detail::has_csc_base<M>);

// const bool conjugate = __detail::is_conjugated(m);
// if constexpr (__detail::has_csr_base<M>) {
// if (conjugate) {
// throw std::runtime_error(
// "oneMKL SYCL backend does not support conjugation for CSR views.");
// }
// return oneapi::mkl::transpose::nontrans;
// } else if constexpr (__detail::has_csc_base<M>) {
// return conjugate ? oneapi::mkl::transpose::conjtrans
// : oneapi::mkl::transpose::trans;
// }
// }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can delete this for now


template <matrix M>
requires __detail::is_csr_view_v<M>
cusparseSpMatDescr_t create_matrix_handle(M&& m) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will keep the same naming scheme for matrix like create_matrix_descriptor.


template <matrix M>
cusparseSpMatDescr_t
get_matrix_handle(M&& m,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
get_matrix_handle(M&& m,
get_matrix_descriptor(M&& m,

Comment on lines -59 to +57
state->set_b_descriptor(b_descr);
state->set_c_descriptor(c_descr);
auto b_handle = __cusparse::create_cusparse_handle(x_base);
auto c_handle = __cusparse::create_cusparse_handle(y);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it currently does not set it to state, you will also need to remove the corresponding part in state

#ifdef SPBLAS_ENABLE_ONEMKL_SYCL
oneapi::mkl::sparse::matrix_handle_t matrix_handle_;
#elif SPBLAS_ENABLE_CUSPARSE
cusparseSpMatDescr_t matrix_handle_;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cusparseSpMatDescr_t matrix_handle_;
cusparseSpMatDescr_t matrix_descriptor_;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants